package com.example.springserurityoauth.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;

/**
 * 授权服务器配置
 */
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        /**
         * 相当于微信授权服务器，用于客户端发送请求获取授权码
         */
            clients.inMemory()
                    //客户端id
                    .withClient("wj-pc")
                    //客户端密码（凭证）
                    .secret(passwordEncoder.encode("112233"))
                    //重定向地址 ，获取授权码
                    .redirectUris("https://www.baidu.com")
                    //授权范围
                    .scopes("all")
                    // false 跳转到授权页面手动点击授权，true 不用手动授权，直接响应授权码，
                    .autoApprove(false)
                    //授权类型，可同时支持多种授权类型
                    .authorizedGrantTypes("authorization_code","refresh_token");
    }
}
